<template>
    <div>
       <el-form :model="policyForm" :rules="rules" ref="policyForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="法规标题" prop="policyName">
    <el-input v-model="policyForm.policyName" size="mini"></el-input>
  </el-form-item>
  <el-form-item label="介绍" prop="policyDes">
    <el-input type="textarea" v-model="policyForm.policyDes"></el-input>
  </el-form-item>
  <el-form-item label="添加时间" prop="policyTime">
    <el-date-picker
      v-model="policyForm.policyTime"
      type="datetime"
      value-format="yyyy-MM-dd hh:mm:ss"
      placeholder="选择日期时间">
    </el-date-picker>
  </el-form-item>
  <el-form-item label="状态" prop="policyState">
    <el-switch v-model="policyForm.policyState"></el-switch>
  </el-form-item>
   <el-form-item>
    <el-button type="primary" @click="submitForm('policyForm')">立即创建</el-button>
    <el-button @click="resetForm('policyForm')">重置</el-button>
  </el-form-item>
</el-form>
    </div>
  </template>
  <script>
  import {addPolicy} from '@/api'
  // 导入组件
 export default {
    name: 'addGoods',
    data() {
      return {
        policyForm: {
          policyName: '',
          policyDes: '',
           policyTime: '',
           policyState: false,
          },
        rules: {
            policyName: [
            { required: true, message: '请输入政策法规名称', trigger: 'blur' },
           
          ],
          policyDes: [
            { required: true, message: '请输入法规内容', trigger: 'change' }
          ]}
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
           console.log(this.policyForm)
           let data ={
             title:this.policyForm.policyName,
             introduce:this.policyForm.policyDes,
             addtime:this.policyForm.policyTime,
             status:this.policyForm.policyState?1:0
           }
           addPolicy(data).then(res=>{
            console.log(res)
            if(res.code == 200){
               this.$message.success('添加成功')
            }else{
              this.$message.error('添加失败，请重试！')
            }
           })
           // 发送请求加参数过去
          } else {
            this.$message('请正确输入表单信息！');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
  </script>
  <style >

  </style>
  